Skip to content

HTTP Status Codes

When we receive a response from a network request, it includes a “status code”. When using the Fetch API, this value can be accessed like this:

async function makeRequest() {
const response = await fetch('/api/some-endpoint');
console.log(response.status); // 200
}

Status codes are 3-digit numbers, and each code corresponds to a different status. Here are some of the most common:

  • 200 — Everything went smoothly!
  • 401 — You're not allowed to access this resource
  • 404 — The server can't find the resource you requested
  • 500 — Something unexpected gone wrong with the server (eg. it's on fire)

These status codes are organized into 5 broad categories:

  1. 100-199 — Informational responses
  2. 200-299 — Successful responses
  3. 300-399 — The request has been redirected
  4. 400-499 — The client made a mistake
  5. 500-599 — Something's wrong with the server

The first category, “informational responses”, is rarely used. I've never seen it in the wild.

200-level statuses are good news. There are several “flavors” here (eg. 201 means that a resource was successfully created), but most APIs will stick with 200.

300-level statuses are generally redirections. 301 means it's moved permanently, 307 means it's moved temporarily.

400-level statuses are usually because of user error, or front-end developer error. The most famous example, 404, happens when the user tries to visit a URL that doesn't exist. Another example, 400, suggests that our request is wrong in some way, like if we forgot to include required data.

Finally, 500-level statuses are server errors. Something broke in the back-end code, and nothing we can do on our end will fix it.

Like HTTP methods, status codes are chosen by developers. It's up to the back-end developer to pick the appropriate code for every given situation. As you might expect, things vary drastically from one server to another.

Some servers ignore status codes entirely, sending 200s for everything. Others are meticulous, sending niche status codes like 417, “Expectation Failed”.

The bottom line: We don't need to memorize 100 different status codes. In my experience, I almost never run into obscure status codes (and when I do, I can easily look them up; MDN has a complete list). It's sufficient to be aware of the 5 categories.